//
//  ChooseTableview.m
//  ChooseDemo
//
//  Created by pro on 2021/11/10.
//

#import "ChooseTableview.h"
#import "ChooseCell.h"

@implementation ChooseTableview

-(instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    self.delegate = self;
    self.dataSource = self;
    self.bounces = NO;
    self.backgroundColor = [UIColor colorWithRed:32/255 green:38/255 blue:50/255 alpha:1];
    
    return self;
}
-(void)setDataArray:(NSArray *)dataArray{
    _dataArray = dataArray;
    [self reloadData];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.dataArray.count;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    static NSString *cellIdentifier = @"ChooseCell";
    ChooseCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    if  (cell ==  nil ) {
        NSArray  *nibs = [[ NSBundle   mainBundle ] loadNibNamed : cellIdentifier   owner : nil   options : nil ];
        cell = [nibs  lastObject ];
        cell. backgroundColor  = [ UIColor   clearColor ];
        [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
     };
    cell.nameLabel.text = [NSString stringWithFormat:@"%@",self.dataArray[indexPath.row]];
    return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    self.didBlock(indexPath);
    self.hidden = YES;
}

@end
